package com.swallow.auth.infrastructure.mysql.handler;

import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.NullValue;
import net.sf.jsqlparser.expression.StringValue;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author: 18310740596@163.com
 * @date: 2024-05-11 13:51:35
 * @version: v1.0
 * @describe: class responsibility
 */
@Component
public class SwallowAuthTenantHandler implements TenantLineHandler {

    private final List<String> ignoreTables = List.of("swallow_auth_account",
                                                      "swallow_auth_account_rel_role",
                                                      "swallow_auth_app",
                                                      "swallow_auth_menu_permission",
                                                      "swallow_auth_uri_permission",
                                                      "swallow_auth_tenant");
    @Override
    public Expression getTenantId() {
        // 根据userNo 获取租户编号
        String tenantNO = "123465";


        return StringUtils.isBlank(tenantNO) ? new NullValue() : new StringValue(tenantNO);
    }

    @Override
    public String getTenantIdColumn() {
        return "tenant_no";
    }

    @Override
    public boolean ignoreTable(String tableName) {
        return ignoreTables.contains(tableName);
    }
}
